home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / Grant's CGI Framework 1.0b14 / Apple Events / AEFunc.c next >
Text File  |  1996-04-11  |  5KB  |  209 lines

  1. /*****
  2.  *
  3.  *    AEFunc.c
  4.  *
  5.  *    This is a support file for "Grant's CGI Framework".
  6.  *    Please see the license agreement that accompanies the distribution package
  7.  *    for licensing details.
  8.  *
  9.  *    Copyright ©1995,1996 by Grant Neufeld
  10.  *    grant@acm.com
  11.  *    http://arpp.carleton.ca/grant/
  12.  *
  13.  *****/
  14.  
  15. #include "MyConfiguration.h"
  16.  
  17. #include <stdlib.h>
  18.  
  19. #include "compiler_stuff.h"
  20. #include "globals.h"
  21.  
  22. #include "DebugUtil.h"
  23. #include "EventUtil.h"
  24. #include "ErrorUtil.h"
  25. #include "MemoryUtil.h"
  26. #include "ProcessUtil.h"
  27.  
  28. #include "AEFunc.h"
  29.  
  30.  
  31. /***  FUNCTIONS  ***/
  32.  
  33. /* IM:IAC 4-35 */
  34. OSErr
  35. AEFuncGotRequiredParams ( AppleEvent *theAppleEvent )
  36. {
  37.     OSErr        theErr;
  38.     DescType    returnedType;
  39.     Size        actualSize;
  40.     
  41.     theErr = AEGetAttributePtr ( theAppleEvent, keyMissedKeywordAttr, typeWildCard,
  42.         &returnedType, NULL, nil, &actualSize );
  43.     if ( theErr == errAEDescNotFound )
  44.     {
  45.         /* all required parameters were retrieved */
  46.         return noErr;
  47.     }
  48.     else if ( theErr == noErr )
  49.     {
  50.         /* required parameter was missed */
  51.         return errAEParamMissed;
  52.     }
  53.     else
  54.     {
  55.         return theErr;
  56.     }
  57. } /* AEFuncGotRequiredParams */
  58.  
  59.  
  60. /* IM:IAC 5-23 */
  61. pascal Boolean
  62. AEFuncAEIdleFunc ( const EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn )
  63. {
  64.     Boolean        theResult = false;
  65.     
  66.     switch ( theEvent->what )
  67.     {
  68.         #if kCompileWithForeground
  69.         
  70.         case updateEvt :
  71.         case activateEvt :
  72.             break;
  73.         
  74.         case osEvt :
  75.             /* CustomAdjustCursor ( theEvent->where, theMouseRgn ); */
  76.             doOsEvt ( theEvent );
  77.             break;
  78.         
  79.         #endif    /* kCompileWithForeground */
  80.  
  81.         
  82.         case nullEvent :
  83.             /* *mouseRgn = theMouseRgn; */
  84.             *sleepTime = gSleepTicks;    /* may need to change to use correct value for app */
  85.             
  86.             /* I'm not 100% certain that this should be here... */
  87.             ProcessGiveTime ( nil );
  88.             break;
  89.     }
  90.     
  91.     return theResult;
  92. } /* AEFuncAEIdleFunc */
  93.  
  94.  
  95. #pragma mark -
  96.  
  97. /* get a string from a parameter */
  98. OSErr
  99. AEGetParamString ( const AppleEvent *theAppleEvent, AEKeyword theAEKeyword, char **theString, char *tempBuffer, long bufferSize )
  100. {
  101.     OSErr        theErr;
  102.     DescType    actualType;
  103.     Size        actualSize;
  104.     
  105.     my_assert ( theString != NULL, "\pAEGetParamString: theString ptr is NULL" );
  106.     my_assert ( *theString == NULL, "\pAEGetParamString: theString is not pointing to NULL" );
  107.     my_assert ( theAppleEvent != NULL, "\pAEGetParamString: theAppleEvent ptr is NULL" );
  108.     my_assert ( tempBuffer != NULL, "\pAEGetParamString: tempBuffer ptr is NULL" );
  109.     
  110.     theErr = AEGetParamPtr ( theAppleEvent, theAEKeyword, typeChar,
  111.         &actualType, (Ptr)tempBuffer, bufferSize, &actualSize );
  112.     
  113.     if ( theErr == noErr )
  114.     {
  115.         my_assert ( actualSize <= bufferSize, "\pAEGetParamString: actual param size too big" );
  116.         
  117.         /* if the parameter was present, allocate space to copy it into destination string */
  118.         *theString = (char *) MemoryNewPtr ( actualSize + 1, &theErr );
  119.         
  120.         if ( *theString != NULL )
  121.         {
  122.             /* copy the tempBuffer into the destination string */
  123.             BlockMove ( tempBuffer, *theString, actualSize );
  124.             
  125.             /* put a null terminator at the end of the string */
  126.             (*theString)[actualSize] = nil;
  127.         }
  128.     }
  129.     
  130.     return theErr;
  131. } /* AEGetParamString */
  132.  
  133.  
  134. /* copy a parameter into an existing string block */
  135. OSErr
  136. AEGetParamStringNoAlloc (
  137.     const AppleEvent *    theAppleEvent,
  138.     AEKeyword            theAEKeyword,
  139.     char *                theString,
  140.     long                 stringSize )
  141. {
  142.     OSErr        theErr;
  143.     DescType    actualType;
  144.     Size        actualSize;
  145.     
  146.     my_assert ( theString != NULL, "\pAEGetParamString: theString ptr is NULL" );
  147.     my_assert ( theAppleEvent != NULL, "\pAEGetParamString: theAppleEvent ptr is NULL" );
  148.     my_assert ( stringSize != nil, "\pAEGetParamString: stringSize is nil" );
  149.     
  150.     theErr = AEGetParamPtr ( theAppleEvent, theAEKeyword, typeChar,
  151.         &actualType, (Ptr)theString, stringSize, &actualSize );
  152.     
  153.     return theErr;
  154. } /* AEGetParamString */
  155.  
  156.  
  157. #pragma segment AppleEvent
  158. /* get a short from a parameter */
  159. OSErr
  160. AEGetParamShort ( const AppleEvent *theAppleEvent, AEKeyword theAEKeyword, short *theShort, char *tempBuffer, long bufferSize )
  161. {
  162.     OSErr        theErr;
  163.     DescType    actualType;
  164.     Size        actualSize;
  165.     
  166.     my_assert ( theShort != NULL, "\pAEGetParamShort: theShort ptr is NULL" );
  167.     my_assert ( theAppleEvent != NULL, "\pAEGetParamShort: theAppleEvent ptr is NULL" );
  168.     my_assert ( tempBuffer != NULL, "\pAEGetParamShort: tempBuffer ptr is NULL" );
  169.     
  170.     theErr = AEGetParamPtr
  171.         ( theAppleEvent, theAEKeyword, typeChar, &actualType, (Ptr)tempBuffer, bufferSize, &actualSize );
  172.     if ( theErr == noErr )
  173.     {
  174.         my_assert ( actualSize <= bufferSize, "\pAEGetParamShort: actual param size too big" );
  175.         
  176.         /* terminate the buffer with a null byte so it will be a proper C string */
  177.         tempBuffer[actualSize] = nil;
  178.         
  179.         *theShort = atoi ( tempBuffer );
  180.     }
  181.     
  182.     return theErr;
  183. } /* AEGetParamShort */
  184.  
  185.  
  186. /* get a long value from a parameter */
  187. OSErr
  188. AEGetParamLong ( const AppleEvent *theAppleEvent, AEKeyword theAEKeyword, long *theLong )
  189. {
  190.     OSErr        theErr;
  191.     DescType    actualType;
  192.     Size        actualSize;
  193.     
  194.     my_assert ( theLong != NULL, "\pAEGetParamShort: theLong ptr is NULL" );
  195.     my_assert ( theAppleEvent != NULL, "\pAEGetParamShort: theAppleEvent ptr is NULL" );
  196.     
  197.     theErr = AEGetParamPtr
  198.         ( theAppleEvent, theAEKeyword, typeLongInteger, &actualType, (Ptr)theLong, sizeof(long), &actualSize );
  199.     if ( theErr == noErr )
  200.     {
  201.         my_assert ( actualSize <= sizeof(long), "\pAEGetParamLong: actual param size too big" );
  202.     }
  203.     
  204.     return theErr;
  205. } /* AEGetParamShort */
  206.  
  207.  
  208. /*****  EOF  *****/
  209.